import 'dart:convert' show json;

import 'package:mahjong/entity/AbstractFormart.dart';

T asT<T>(dynamic value) {
  if (value is T) {
    return value;
  }
  return null;
}

class VerificationMode implements AbstractFormart {
  VerificationMode({
    this.backGroundImage,
    this.moveImage,
    this.scale,
    this.id,
    this.x,
    this.y,
  });

  factory VerificationMode.fromJson(Map<String, dynamic> jsonRes) =>
      jsonRes == null
          ? null
          : VerificationMode(
              backGroundImage: asT<String>(jsonRes['backGroundImage']),
              moveImage: asT<String>(jsonRes['moveImage']),
              scale: asT<double>(jsonRes['scale']),
              id: asT<String>(jsonRes['id']),
              x: asT<Object>(jsonRes['x']),
              y: asT<Object>(jsonRes['y']),
            );

  String backGroundImage;
  String moveImage;
  double scale;
  String id;
  double x;
  double y;

  Map<String, dynamic> toJson() => <String, dynamic>{
        'backGroundImage': backGroundImage,
        'moveImage': moveImage,
        'scale': scale,
        'id': id,
        'x': x,
        'y': y,
      };

  @override
  String toString() {
    return json.encode(this);
  }

  @override
  caseToEntity(Map<String, dynamic> jsonRes) { 
    return VerificationMode.fromJson(jsonRes);
  }
}
